package com.dqhl.community.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.widget.TextView;

/**
 * Created by Administrator on 2016/9/22.
 */
public class GetVersion {
    public static final String getVersion(Context context, TextView tv_vesion) {
        // 获取packagemanager的实例
        String version = "";
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = null;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        version = packInfo.versionName;
        tv_vesion.setText(version.toString());
        return version;
    }
}
